//! # Core Library of CS2 System
//!
//! This library provides the core data structures and functions for CS2 System,
//! including the cache block, cache table, and error handling.
//!
//! This library can be used in C/C++ programs, see
//! [cs2s-ccapi](../cs2s_ccapi/index.html) for more details.

#![cfg_attr(all(coverage_nightly, test), feature(coverage_attribute))]

#[cfg(not(unix))]
compile_error!("CS2 System only supports Unix platform");

pub mod cache;
pub mod command;
pub mod error;
pub mod route;
pub mod sign;
pub mod utils;

/// Build information of the library.
pub mod build_info {
    use std::sync::LazyLock;

    use generated::*;

    mod generated {
        include!(concat!(env!("OUT_DIR"), "/built.rs"));
    }

    /// Get the version string of the library.
    pub fn version() -> &'static str {
        static VERSION: LazyLock<String> = LazyLock::new(|| {
            let pkg_version = env!("CARGO_PKG_VERSION");
            let git_version = GIT_COMMIT_HASH_SHORT.unwrap_or("unknown");

            if let Some(true) = GIT_DIRTY {
                format!("{} ({}-dirty)", pkg_version, git_version)
            } else {
                format!("{} ({})", pkg_version, git_version)
            }
        });

        &VERSION
    }

    #[cfg(test)]
    mod test {
        use coverage_helper::test;

        use super::*;

        #[test]
        fn version_check() {
            let v = version();
            assert!(v.starts_with(env!("CARGO_PKG_VERSION")));
            assert_eq!(v, version());
        }
    }
}
